#include <Arduino.h>
#include<Servo.h>
#define ypin A0
#define xpin A1
Servo x;
Servo y;
int xvalue;
int yvalue;
void setup() {
  // put your setup code here, to run once:
  pinMode(xpin,INPUT);
  pinMode(ypin,INPUT);
  x.attach(8);
  y.attach(9);
  x.write(90);   //初始位置和舵机变动范围可以电机安装后根据情况调整
  y.write(86);   //初始位置和舵机变动范围可以电机安装后根据情况调整  
}
void fliter(int &x,int &y)
{
  x=0;
  y=0;
  for(int i=0;i<30;i++)
  {
    x+=analogRead(xpin);
    y+=analogRead(ypin);
  }
  x/=30;
  y/=30;
}
void loop() {
  // put your main code here, to run repeatedly:
  fliter(xvalue,yvalue);
  xvalue=map(xvalue,0,1023,80,100);
  yvalue=map(yvalue,0,1023,76,96);
  
  x.write(xvalue);
  y.write(yvalue);
 
}